package top.cardone.security.shiro.func;

import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.shiro.SecurityUtils;
import top.cardone.core.util.func.Func0;
import top.cardone.core.util.func.Func1;

/**
 * Created by yht on 16-3-28.
 */
public class ReadValueFunc implements Func0<Object>, Func1<Object, Object> {
	@Setter
	private Object key;

	@Override
	public Object func() {
		Object attribute = SecurityUtils.getSubject().getSession().getAttribute(this.key);

		return attribute;
	}

	@Override
	public Object func(Object obj) {
		return ObjectUtils.defaultIfNull(this.func(), obj);
	}
}
